#include "videobox.h"
#include "ui_videobox.h"
#include <QDir>
VideoBox::VideoBox(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::VideoBox)
{
    ui->setupUi(this);

    ui->delVideoBtn->hide();

    playerPage = new PlayerPage();

    ui->imageBox->installEventFilter(this);
    ui->videoTitle->installEventFilter(this);
}

VideoBox::~VideoBox()
{
    delete ui;
}

bool VideoBox::eventFilter(QObject *watched, QEvent *event)
{
    if(ui->imageBox == watched || ui->videoTitle == watched)
    {
        if(event->type() == QEvent::MouseButtonPress)
        {
            onPlayClicked();
            return true;
        }
    }
    return QObject::eventFilter(watched, event);
}

void VideoBox::onPlayClicked()
{
    // 显示播放窗口
    playerPage->show();

    // 获取视频路径, 将视频路径交给playerPage, 让playerPage完成视频播放
    QDir dir = QDir::current();
    dir.cdUp();
    dir.cdUp();
    QString videoPath = dir.absolutePath();
    videoPath += "/videos/111.m3u8";
    playerPage->startPlaying(videoPath);
}
